package com.meilai.project.util;

import lombok.Data;

import java.time.LocalDate;

/**
 * @author xchen
 * @since 2022-04-17
 */
@Data
public class DateRange {
    public DateRange() {
    }

    public DateRange(LocalDate beginDate, LocalDate endDate) {
        this.beginDate = beginDate;
        this.endDate = endDate;
    }

    /**
     * 开始日期
     */
    private LocalDate beginDate;
    /**
     * 结束日期
     */
    private LocalDate endDate;

    /**
     * 业务逻辑字段
     */
    private boolean isNeed = true;

    public boolean isTwoWeekAgo() {
        LocalDate date = LocalDate.now().minusWeeks(2);
        return date.compareTo(beginDate) >= 0 && date.compareTo(endDate) <= 0;
    }

    public boolean isCurrentWeekOrFuture() {
        LocalDate today = LocalDate.now();
        return today.compareTo(beginDate) >= 0 && today.compareTo(endDate) <= 0 ||
                beginDate.compareTo(today) >= 0;
    }

    public long length() {
        return this.endDate.plusDays(1).toEpochDay() - this.beginDate.toEpochDay();
    }

}
